home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#40 (Jan 89)
/
FinderControls
/
Shell texte
< prev
Wrap
Text File
|
1988-05-02
|
4KB
|
154 lines
{**********************************************}
{ Put this file in the Shell Project after DAPasLib, MacTraps, ROM85lib and ROM85,}
{ put also CDEF text if you plan to improve and debug it. }
{ Don't forget to "Use resource file" "CDEF Code" in "Run options" }
{ of menu "Project". }
{ This resource file must contain the WIND ,CNTL, MENU, ICN#, ICON,}
{ MDEF and CDEF resource. }
{**********************************************}
PROGRAM shell;
USES
ROM85;
{ , CDEFIcones; { only for denugging purposes }
CONST
RestState = 0;
SelectState = 1;
OpenState = 2;
SelectOpenState = 3;
ThrownAwayState = 4;
MenuReturnState = 5;
TYPE
CDEFcodeHdl = ^CDEFcodePtr;
CDEFcodePtr = ^CDEFcodeRecord;
CDEFcodeRecord = RECORD
jump : integer;
address : ProcPtr;
END;
VAR
whichWindow, myWindow : WindowPtr;
whichControl, theTrash : ControlHandle;
myCDEF : CDEFcodeHdl;
theEvent : EventRecord;
theControl : ControlHandle;
mouse : point;
FakeRect : rect;
done : boolean;
i : integer;
PROCEDURE ProcessMenu (where : longint);
VAR
MenuNb, ItemNb : integer;
dummy : longint;
i : integer;
BEGIN
MenuNb := HiWord(where);
ItemNb := LoWord(where);
CASE MenuNb OF
1 :
FOR i := 1 TO ItemNb DO
BEGIN
SysBeep(5);
Delay(10, dummy);
END;
OTHERWISE
;
END;
END;
PROCEDURE ProcessEvent;
VAR
myWindowPeek : WindowPeek;
dummy : integer;
BEGIN
CASE theEvent.what OF
UpDateEvt :
BEGIN
whichWindow := WindowPtr(theEvent.message);
beginUpDate(whichWindow);
IF whichWindow = myWindow THEN
BEGIN
EraseRgn(myWindow^.VisRgn);
UpdtControl(myWindow, myWindow^.VisRgn);
END;
endUpDate(whichWindow);
END;
MouseDown :
BEGIN
CASE FindWindow(theEvent.where, whichWindow) OF
inContent :
BEGIN
mouse := theEvent.where;
GlobalToLocal(mouse);
IF FindControl(mouse, whichWindow, whichControl) <> 0 THEN
BEGIN
{ choose DragControl or TrackControl as you prefere : }
{ dummy:=TrackControl(theControl,mouse,pointer(-1)) }
SetRect(FakeRect, 0, 0, 0, 0);
DragControl(whichControl, mouse, FakeRect, FakeRect, noConstraint);
IF GetCtlValue(whichControl) = ThrownAwayState THEN
BEGIN
theTrash := ControlHandle(GetCRefCon(whichControl));
SetCtlValue(theTrash, GetCtlValue(theTrash) - 1);
DisposeControl(whichControl);
END
ELSE IF GetCtlValue(whichControl) = MenuReturnState THEN
BEGIN
ProcessMenu(GetCRefCon(whichControl));
{ the Control has already been re-drawn in RestState, }
{ so we don't need to re-redraw it again.}
whichControl^^.ContrlValue := 0;
END
ELSE IF GetCtlValue(whichControl) = SelectOpenState THEN
BEGIN
dummy := NoteAlert(128, NIL);
SetCtlValue(whichControl, RestState);
END
ELSE
;
END;
END;
inGoAway :
IF TrackGoAway(whichWindow, theEvent.where) THEN
done := true;
inDrag :
DragWindow(whichWindow, theEvent.where, ScreenBits.bounds);
OTHERWISE
;
END;
END;
OTHERWISE
;
END;
END;
BEGIN
{ create a intermediate CDEF resource : }
{myCDEF := CDEFcodeHdl(NewHandle(sizeof(CDEFcodeRecord))); { for debugging only }
{myCDEF^^.jump := $4EF9; { for debugging only }
{myCDEF^^.address := @main; { for debugging only }
{AddResource(handle(myCDEF), 'CDEF', 128, ''); { for debugging only }
myWindow := GetNewWindow(128, NIL, pointer(-1));
SetPort(myWindow);
{BackPat(gray); { or whatever background pattern you wish }
InsertMenu(GetMenu(128), -1);
FOR i := 128 TO 133 DO
theControl := GetNewControl(i, myWindow);
done := false;
SetCursor(arrow);
FlushEvents(EveryEvent, 0);
ShowWindow(myWindow);
REPEAT
IF GetNextEvent(EveryEvent, theEvent) THEN
ProcessEvent;
UNTIL done;
DisposeWindow(myWindow);
{RmveResource(handle(myCDEF)); { for debugging only }
{DisposHandle(handle(myCDEF)); { for debugging only }
END.